<?php
// +----------------------------------------------------------------------
// | MyCentOS
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.mycentos.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 琥珀 <317559272@qqq.com><http://www.mycentos.com>
// +----------------------------------------------------------------------
// | @date  : 2015-04-09 14:43:42
// +----------------------------------------------------------------------
// | @Last Modified by:  琥珀
// +----------------------------------------------------------------------
// | @Last Modified time: 2015-04-09 15:57:48
// +-----------------------------------------------------------------------
/**
 * 登陆模型
 */
namespace Admin\Model;
use Think\Model;

Class LoginModel extends Model{
    protected $tableName = 'user';

    public function login($username,$password){
        if ($username=="") {
            return 2;
        }elseif($password==""){
            return 3;
        }
        $model = M('user');
        $map['username'] = $username;
        $user = $model->where($map)->find();
        if (!$user) {
            return 4;
        }
        if ($user['password']==md5($password)) {
            $this->autologin($user);
            return 1;
        }
        if ($user['password']!==md5($password)) {
             return 4;
        }else{
            return false;
        }
    }
    public function autologin($user){
        session('user_auth',$user);
    }
}
?>